import request from "@/utils/index.js";

// 获取分页合同列表
export const getContractPageListService = (currentPage, pageSize, cusName, empName) => {
    return request.get("/api/contract/page", {params: {currentPage, pageSize, cusName, empName}});
}

// 获取全部合同列表
export const getContractListService = () => {
    return request.get("/api/contract/list");
}

//合同新增
export const addContractService = (contract) => {
    return request.post("/api/contract", contract);
}

//合同删除
export const deleteContractService = (ids) => {
    // 将多个 ID 用逗号连接起来
    //如果 ids 是一个数组，则将数组中的元素用逗号连接起来
    if (Array.isArray(ids)) {
        ids = ids.join(",");
    }

    // 如果 ids 是一个数字，则将其转换为字符串
    if (typeof ids === "number") {
        ids = ids.toString();
    }
    // const idsParam = ids.join(",");
    return request.delete(`/api/contract?ids=${ids}`);
};

// 合同修改
export const updateContractService = (contract) => {
    console.log("updateContractService");
    console.log(contract);
    return request.put("/api/contract", contract);
}

// 根据销售人员id查询合同
export const getContractByEmpIdService = (currentPage, pageSize, empId) => {
    return request.get(`/api/contract/${empId}`, {params: {currentPage, pageSize}});
}